FROM maven:3.6.1-jdk-8-alpine as source

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk add git \
    && rm /var/cache/apk/*
#ENV MAVEN_PRIVATE_REGISTRY=http://192.168.112.62:8081/repository/maven-public/
ENV MAVEN_PRIVATE_REGISTRY=https://maven.aliyun.com/repository/central
RUN echo "<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\" \
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \
xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0 \
                    https://maven.apache.org/xsd/settings-1.0.0.xsd\"> \
<localRepository>/usr/share/maven/ref/repository</localRepository> \
<mirrors> \
    <mirror> \
        <id>local</id> \
        <name>central</name> \
        <url>"$MAVEN_PRIVATE_REGISTRY"</url> \
        <mirrorOf>external:*</mirrorOf> \
    </mirror> \
</mirrors> \
</settings>" > /usr/share/maven/conf/settings.xml
WORKDIR /app
COPY pom.xml ./pom.xml
RUN mvn package -Dmaven.test.skip=true
COPY src ./src
RUN mvn package -Dmaven.test.skip=true
ARG JAR_FILE=target/*.jar
RUN cp $JAR_FILE app.jar
RUN rm -rf src pom.xml target /usr/share/maven/ref/repository

RUN git clone https://gitee.com/consolelog/Chronomancer.git
COPY config*.json /app/
ENV CHRONOMANCER_SOURCE_PATH=/app/Chronomancer
ENV CHRONOMANCER_CONFIG_PATH=/app
ENV CHRONOMANCER_CONFIG_LANGUAGE=zh
RUN java -jar app.jar

FROM dart:stable AS build

WORKDIR /app
RUN dart pub global activate webdev
COPY --from=source /app/Chronomancer/pubspec.* ./
RUN dart pub get

COPY --from=source /app/Chronomancer .
RUN dart pub get --offline
RUN dart pub global run webdev build
#RUN dart pub global run webdev serve web:30001

FROM nginx:alpine

COPY --from=build /app/build /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]

#FROM dart:stable AS build
#
#WORKDIR /app
#COPY pubspec.* ./
#RUN dart pub get
#RUN dart pub global activate webdev
#COPY . .
#RUN dart pub get --offline
#RUN dart pub global run webdev build
#
#FROM nginx:alpine
#
#COPY --from=build /app/build /usr/share/nginx/html
#CMD ["nginx", "-g", "daemon off;"]

